///////////////////////////////////////////////////////////////////////////////
//
// Licensed under the MIT License
//
// Copyright (c) 2010 Chris Colinsky
// All Rights Reserved
//
// version	0.5
// http://code.google.com/p/sugarcookie/
// http://code.google.com/p/sugarcookie/wiki/License
//
////////////////////////////////////////////////////////////////////////////////

package sugarcookie.components.videoPlayer {
	import flash.text.TextField;
	
	import sugarcookie.display.SpriteBase;
	import sugarcookie.text.UIText;
	import sugarcookie.utils.StringUtil;
	
	public class BasicTimecode extends SpriteBase {
		private var _duration:UIText;
		private var _position:UIText;
		
		public function BasicTimecode(props:Object=null) {
			super(props);
			assignGraphics();
		}
		
		final public function updateTimeCode(position:Number,duration:Number=-1):void {
			//trace("## "+Math.round(position)+", "+int(duration));
			_position.htmlText = StringUtil.formatTimecode(Math.ceil(position));
			if (duration>0) _duration.htmlText = StringUtil.formatTimecode(int(duration));
		}
		
		final public function set duration(value:TextField):void { addChild(_duration = new UIText("00:00",{},value)); }
		final public function set position(value:TextField):void { addChild(_position = new UIText("00:00",{},value)); }
		
		protected function assignGraphics():void {
			// overridden in subclass
		}
	}
}